package algotithm.weekendrace.leetcode238.test3;

/**
 * @author 25068
 * @Date 2021/4/25 11:15
 * @Title 5740. 所有元音按顺序排布的最长子字符串
 */
class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        String word = "aeiaaioaaaaeiiiiouuuooaauuaeiu";
        int res = solution.longestBeautifulSubstring(word);
        System.out.println(res);
    }

    public int longestBeautifulSubstring(String word) {
        char cur = 'a';
        int cnt = 0, max = 0, state = 0;
        int[] cTI = new int[256];
        cTI['a'] = 1;
        cTI['e'] = 2;
        cTI['i'] = 4;
        cTI['o'] = 8;
        cTI['u'] = 16;
        for(char c : word.toCharArray()) {
            if(c >= cur) {
                cnt++;
            } else {
                cnt = 1;
                state = 0;
            }
            cur = c;
            state |= cTI[c];
            if(state == 31) {
                max = Math.max(max, cnt);
            }
            //System.out.println(state + " " + cnt + " " + max);
        }
        return max;
    }
}
